<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="POSTheader()">异步按钮</button>

    <script>
        function POSTheader() {
            let xml = new XMLHttpRequest();
            xml.open("POST", "http://localhost:8080/api/header", true);
            xml.setRequestHeader("content-type", "application/json")
            xml.setRequestHeader("token", "868")
            let jsonObject = {
                "val": "800",
                "data": true
            }
            xml.send(JSON.stringify(jsonObject));
            xml.onreadystatechange = function () {
                if (xml.readyState == 4 && xml.status == 200) {
                    let jsontest = xml.responseText;
                    let jsonobj = JSON.parse(jsontest);
                    console.log(jsonobj);
                }
            }

        }
    </script>

</body>

</html>